home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / axcool / clspnttl.cls < prev    next >
Text File  |  1998-10-22  |  44KB  |  968 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "PaintEffects"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Attribute VB_Description = "Provides methods for painting transparent and disabled looking images."
  11. Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
  12. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  13.  
  14. '  MultiUse = -1  'True
  15. '  Persistable = 0  'NotPersistable
  16. '  DataBindingBehavior = 0  'vbNone
  17. '  DataSourceBehavior = 0   'vbNone
  18. '  MTSTransactionMode = 0   'NotAnMTSObject
  19. 'End
  20. Option Explicit
  21. ' ------------------------------------------------------------------------
  22. '      Copyright ⌐ 1997 Microsoft Corporation.  All rights reserved.
  23. '
  24. ' You have a royalty-free right to use, modify, reproduce and distribute
  25. ' the Sample Application Files (and/or any modified version) in any way
  26. ' you find useful, provided that you agree that Microsoft has no warranty,
  27. ' obligations or liability for any Sample Application Files.
  28. ' ------------------------------------------------------------------------
  29. '-------------------------------------------------------------------------
  30. 'This class provides methods needed for painting masked bitmaps and
  31. 'disabled or embossed bitmaps and icons
  32. '-------------------------------------------------------------------------
  33.  
  34. Private m_hpalHalftone As Long  'Halftone created for default palette use
  35.  
  36. '-------------------------------------------------------------------------
  37. 'Purpose:   Creates a disabled-appearing (grayed) bitmap, given any format of
  38. '           input bitmap.
  39. 'In:
  40. '   [hdcDest]
  41. '           Device context to paint the picture on
  42. '   [xDest]
  43. '           X coordinate of the upper left corner of the area that the
  44. '           picture is to be painted on. (in pixels)
  45. '   [yDest]
  46. '           Y coordinate of the upper left corner of the area that the
  47. '           picture is to be painted on. (in pixels)
  48. '   [Width]
  49. '           Width of picture area to paint in pixels.  Note: If this value
  50. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  51. '           instead of the pictures' width in pixels), this procedure will
  52. '           attempt to create bitmaps that require outrageous
  53. '           amounts of memory.
  54. '   [Height]
  55. '           Height of picture area to paint in pixels.  Note: If this
  56. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  57. '           twips instead of the pictures' height in pixels), this
  58. '           procedure will attempt to create bitmaps that require
  59. '           outrageous amounts of memory.
  60. '   [picSource]
  61. '           Standard Picture object to be used as the image source
  62. '   [xSrc]
  63. '           X coordinate of the upper left corner of the area in the picture
  64. '           to use as the source. (in pixels)
  65. '           Ignored if picSource is an Icon.
  66. '   [ySrc]
  67. '           Y coordinate of the upper left corner of the area in the picture
  68. '           to use as the source. (in pixels)
  69. '           Ignored if picSource is an Icon.
  70. '   [clrMask]
  71. '           Color of pixels to be masked out
  72. '   [clrHighlight]
  73. '           Color to be used as outline highlight
  74. '   [clrShadow]
  75. '           Color to be used as outline shadow
  76. '   [hPal]
  77. '           Handle of palette to select into the memory DC's used to create
  78. '           the painting effect.
  79. '           If not provided, a HalfTone palette is used.
  80. '-------------------------------------------------------------------------
  81. Public Sub PaintDisabledStdPic(ByVal hdcDest As Long, _
  82.                                 ByVal xDest As Long, _
  83.                                 ByVal yDest As Long, _
  84.                                 ByVal Width As Long, _
  85.                                 ByVal Height As Long, _
  86.                                 ByVal picSource As StdPicture, _
  87.                                 ByVal xSrc As Long, _
  88.                                 ByVal ySrc As Long, _
  89.                                 Optional ByVal clrMask As OLE_COLOR = vbWhite, _
  90.                                 Optional ByVal clrHighlight As OLE_COLOR = vb3DHighlight, _
  91.                                 Optional ByVal clrShadow As OLE_COLOR = vb3DShadow, _
  92.                                 Optional ByVal hPal As Long = 0)
  93. Attribute PaintDisabledStdPic.VB_Description = "Paints a disabled appearing image (embossed) given a source picture object."
  94.     Dim hDcSrc As Long         'HDC that the source bitmap is selected into
  95.     Dim hbmMemSrcOld As Long
  96.     Dim hbmMemSrc As Long
  97.     Dim udtRect As RECT
  98.     Dim hbrMask As Long
  99.     Dim lMaskColor As Long
  100.     Dim hDcScreen As Long
  101.     Dim hPalOld As Long
  102.     
  103.     'Verify that the passed picture is not nothing
  104.     If picSource Is Nothing Then GoTo PaintDisabledDC_InvalidParam
  105.     Select Case picSource.Type
  106.         Case vbPicTypeBitmap
  107.             'Select passed picture into an HDC
  108.             hDcScreen = GetDC(0&)
  109.             'Validate palette
  110.             If hPal = 0 Then
  111.                 hPal = m_hpalHalftone
  112.             End If
  113.             hDcSrc = CreateCompatibleDC(hDcScreen)
  114.             hbmMemSrcOld = SelectObject(hDcSrc, picSource.handle)
  115.             hPalOld = SelectPalette(hDcSrc, hPal, True)
  116.             RealizePalette hDcSrc
  117.             
  118.             'Draw the bitmap
  119.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hDcSrc, xSrc, ySrc, clrMask, clrHighlight, clrShadow, hPal
  120.             
  121.             SelectObject hDcSrc, hbmMemSrcOld
  122.             SelectPalette hDcSrc, hPalOld, True
  123.             RealizePalette hDcSrc
  124.             DeleteDC hDcSrc
  125.             ReleaseDC 0&, hDcScreen
  126.         Case vbPicTypeIcon
  127.             'Create a bitmap and select it into a DC
  128.             hDcScreen = GetDC(0&)
  129.             'Validate palette
  130.             If hPal = 0 Then
  131.                 hPal = m_hpalHalftone
  132.             End If
  133.             hDcSrc = CreateCompatibleDC(hDcScreen)
  134.             hbmMemSrc = CreateCompatibleBitmap(hDcScreen, Width, Height)
  135.             hbmMemSrcOld = SelectObject(hDcSrc, hbmMemSrc)
  136.             hPalOld = SelectPalette(hDcSrc, hPal, True)
  137.             RealizePalette hDcSrc
  138.             'Draw Icon onto DC
  139.             udtRect.Bottom = Height
  140.             udtRect.Right = Width
  141.             OleTranslateColor clrMask, 0&, lMaskColor
  142.             SetBkColor hDcSrc, lMaskColor
  143.             hbrMask = CreateSolidBrush(lMaskColor)
  144.             FillRect hDcSrc, udtRect, hbrMask
  145.             DeleteObject hbrMask
  146.             DrawIcon hDcSrc, 0, 0, picSource.handle
  147.             'Draw Disabled image
  148.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hDcSrc, 0&, 0&, clrMask, clrHighlight, clrShadow, hPal
  149.             'Clean up
  150.             SelectPalette hDcSrc, hPalOld, True
  151.             RealizePalette hDcSrc
  152.             DeleteObject SelectObject(hDcSrc, hbmMemSrcOld)
  153.             DeleteDC hDcSrc
  154.             ReleaseDC 0&, hDcScreen
  155.         Case Else
  156.             GoTo PaintDisabledDC_InvalidParam
  157.     End Select
  158.     Exit Sub
  159. PaintDisabledDC_InvalidParam:
  160.     'Error.Raise giINVALID_PICTURE
  161.     Exit Sub
  162. End Sub
  163.  
  164. '-------------------------------------------------------------------------
  165. 'Purpose:   Creates a disabled-appearing (grayed) bitmap, given any format of
  166. '           input bitmap.
  167. 'In:
  168. '   [hdcDest]
  169. '           Device context to paint the picture on
  170. '   [xDest]
  171. '           X coordinate of the upper left corner of the area that the
  172. '           picture is to be painted on. (in pixels)
  173. '   [yDest]
  174. '           Y coordinate of the upper left corner of the area that the
  175. '           picture is to be painted on. (in pixels)
  176. '   [Width]
  177. '           Width of picture area to paint in pixels.  Note: If this value
  178. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  179. '           instead of the pictures' width in pixels), this procedure will
  180. '           attempt to create bitmaps that require outrageous
  181. '           amounts of memory.
  182. '   [Height]
  183. '           Height of picture area to paint in pixels.  Note: If this
  184. '